package com.songwp.service.impl;

import com.songwp.entity.CategoryTreeNode;
import com.songwp.mapper.AreaTreeMapper;
import com.songwp.service.AreaTreeService;
import com.songwp.untils.TreeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Project:
 * @Description:
 * @Auther: songwp
 * @Date: 2022/2/26 18:52
 **/
@Service
public class AreaTreeServiceImpl implements AreaTreeService {

    @Resource
    AreaTreeMapper areaTreeMapper;


    @Override
    public List<CategoryTreeNode> getSymptomTreeJson() {
        //从数据库获取数据的list（一次性获取的所有数据）
        List<CategoryTreeNode> list= areaTreeMapper.selectSymptomTreeNodeJson();
        List<CategoryTreeNode> resultList = new ArrayList<>();
        TreeUtil treeUtilNew = new TreeUtil();
        resultList = treeUtilNew.build(list); //进行封装
        return resultList; //返回树形结构json
    }

    @Override
    public CategoryTreeNode selectByName(String name) {
        return areaTreeMapper.selectByName(name);
    }
}
